#!/usr/bin/ruby
# -*- ruby -*-
#
# http://www.reddit.com/r/dailyprogrammer/comments/1268t4/10272012_challenge_108_easy_scientific_notation/

ARGV.each do |i|
    unless /\^/.match(i)
        f = i.to_f

        sign = (f > 0.0) ? 1 : -1

        f *= sign

        exp = 0

        until 1 <= f && f < 10
            if f >= 10
                exp += 1

                f /= 10
            elsif f <= 1
                exp -= 1

                f *= 10
            end
        end

        puts "#{i} => #{sign * f}x10^#{exp}"
    else
        base, pow_exp = i.split('x')
        pow, exp = pow_exp.split('^')

        puts "#{i} => #{base.to_f * (pow.to_f ** exp.to_f)}"
    end
end
